#include <bits/stdc++.h>
#define sc(x) scanf("%lld", &(x))
#define pr(x) printf("%lld\n", (x))
#define rep(i, l, r) for (int i = l; i <= r; ++i)
using namespace std;
typedef long long ll;
const int N = 3e3 + 7;
const int mod = 1e9 + 7;
int a[N][N];  // 邻接矩阵存图
const int n = 2021;// 点数
void build() {
    rep(i, 1, n) rep(j, 1, n) {
        if (abs(i - j) <= 21) a[i][j] = a[j][i] = i / __gcd(i, j) * j;
    }
}
ll dis[N];
bool vis[N];
void spfa(int ori) {
    fill(dis, dis + n + 1, LLONG_MAX);
    dis[ori] = 0;
    queue<int> q;
    vis[ori] = 1;
    q.push(1);
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        vis[x] = 0;
        rep(i, 1, n) if (x != i && abs(x - i) <= 21) {
            if (dis[x] + a[x][i] < dis[i]) {
                dis[i] = dis[x] + a[x][i];
                if (!vis[i]) {
                    vis[i] = 1;
                    q.push(i);
                }
            }
        }
    }
}
int main() {
    build();
    spfa(1);
    pr(dis[n]);
    return 0;
}
